class Solution {
    final private static int[][] DIR = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

    public void solve(char[][] board) {
        int H = board.length, W = board[0].length;
        boolean[][] invalid = new boolean[H][W];
        int r = 0, c = 0;

        for (int[] dir : DIR) {
            while (true) {
                int nextR = r + dir[0];
                int nextC = c + dir[1];
                if (!inBounds(board, nextR, nextC)) {
                    break;
                }
                r = nextR;
                c = nextC;
                if (board[r][c] == 'O' && !invalid[r][c]) {
                    dfs(board, r, c, invalid);
                }
            }
        }

        for (r = 1; r < H - 1; r++) {
            for (c = 1; c < W - 1; c++) {
                if (!invalid[r][c]) {
                    board[r][c] = 'X';
                }
            }
        }
    }

    private void dfs(char[][] board, int r, int c, boolean[][] visited) {
        visited[r][c] = true;
        for (int[] dir : DIR) {
            int nextR = r + dir[0];
            int nextC = c + dir[1];
            if (inBounds(board, nextR, nextC) && board[nextR][nextC] == 'O' && !visited[nextR][nextC]) {
                dfs(board, nextR, nextC, visited);
            }
        }
    }

    private boolean inBounds(char[][] board, int r, int c) {
        int H = board.length, W = board[0].length;
        return r >= 0 && r < H & c >= 0 && c < W;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}